import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot} from '@angular/router';
import {AppService} from '../app.service';
import {BasicService} from './basic.service';
import {LoginDto} from './basic.model';

@Injectable()
export class BaseRouteFilter implements CanActivate {
  constructor(public basicService: BasicService,
              public appService: AppService) {
  }

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    const loginDto: LoginDto = this.basicService.getRefreshToken();
    if (loginDto) {
      return true;
    } else {
      this.basicService.logOut();
      return false;
    }
  }
}
